#!/usr/bin/env python
# encoding: utf-8
'''
@author: gjzuo
@license: (C) Copyright 1999-2018, Fiberhome Telecommunication Technologies Co.,LTD.
@contact: gjzuo@fiberhome.com
@software: fiberhome
@file: errorCode.py
@time: 2018/4/18 15:12
@desc:
'''


class CustomError():
    # 默认的返回码
    status_code = 0

    # 自己定义了一个 return_code，作为更细颗粒度的错误代码
    def __init__(self, return_code=0, status_code=0):
        self.return_code = return_code
        if status_code is not 0:
            self.status_code = status_code

    # 构造要返回的错误代码和错误信息的 dict
    def getErrorInfo(self, errorCode, errorType, lang):
        if errorType == 1:
            return cuttomError[errorCode][lang]
        else:
            return cuttomError[errorCode][lang]




INVALID_REQUEST         = 10000
INVALID_CLIENT          = 10001
INVALID_GRANT           = 10002
UNAUTHORIZED_CLIENT     = 10003
EXPIRED_TOKEN           = 10004

cuttomError = {
    INVALID_REQUEST: {
        "cn": "非法的请求参数",
        "en": "Invalid request"
    },
    INVALID_CLIENT: {
        "cn": "用户认证失败",
        "en": "Invalid client"
    },
    INVALID_GRANT: {
        "cn": "非法的授权信息",
        "en": "Invalid grant"
    },
    UNAUTHORIZED_CLIENT: {
        "cn": "应用没有被授权，无法使用所指定的grant_type",
        "en": "Unauthorized client"
    },
    EXPIRED_TOKEN: {
        "cn": "提供的更新令牌已过期",
        "en": "Expired token"
    }
}


